package com.portico.dept.solarch

import com.portico.security.User

class Project implements Serializable {

  String name;
  String description;
  String projectNumber ;
  String wikiUrl ;
  String sharePointUrl ;
  String sponsor;
  String technicalManager ;
  
  String projectType;
  String projectSubType;
  String projectState = "Open" ;

  Boolean showProjectDashboard = true ;


  Date startDate;
  Date endDate;


  static hasMany = [recurringStatus: ProjectStatus,
          forecast:ProjectForecast, roster : ProjectTeamMember,
          releaseDetails:ReleaseDetail,  qualityDetails : ProjectQuality,
          risks: ProjectRisks, projectAdmins :User, testCaseExecutionHistory:TestCaseExecutionHistory]

  static mapping = {
        recurringStatus lazy:false
        forecast lazy:false
        roster lazy:false
        releaseDetails lazy:false
        qualityDetails lazy:false, sort:'createdOn', order:'desc'
        risks: lazy:false
        projectAdmins  lazy:false
        recurringStatus lazy:false , sort:'statusDate', order:'desc'
  }

  static mappedBy = [
        recurringStatus: 'project',
        forecast:'project',  roster:'project'  ,
        releaseDetails:'project', qualityDetails:'project',
          risks:'project', testCaseExecutionHistory:'project'
  ]
  

   // new Project (name:"Test Project", projectType: "Internal", projectSubType:"Other", startDate:new Date(), endDate: (new Date())+7 ). save(failOnError:true)
  static constraints = {
    name(blank: false, maxSize: 200, minSize: 6, unique: true)
    description (maxSize:4000)
    projectType (shared:"projectTypeList")
    projectSubType (shared:"projectSubTypeList")
    projectState inList:(['Open', 'Completed', 'OnIce',  'Closed'])
    startDate(blank:false)
    endDate (validator : {val, obj ->
      if (val != null) {
        return val.after (obj.startDate)
      } else
        return true
    })
    sharePointUrl url:true
    wikiUrl url:true
    showProjectDashboard blank:false

  }

  String toString() {
    name ; 
  }
}
